#pragma once
#ifndef SCRIPT__TAB__WIDGET__HH__
#define SCRIPT__TAB__WIDGET__HH__

#include <qboxlayout.h>
#include <qplaintextedit.h>
#include <qtabwidget.h>
#include <map>
#include "ScriptEditorPrereqs.h"

namespace Lit
{
	namespace Editor
	{
		class ScriptTabWidget : public QTabWidget
		{
			Q_OBJECT
		protected:
			typedef std::map<std::string, ScriptEditorWidget*> PageMap;

			PageMap						pages;
			InstancePtr					mInstance;
			std::string					mBaseName;
			std::string					mExt;

		public:
			ScriptTabWidget( QWidget * parent = 0 );
			~ScriptTabWidget( );
			
			void setExtension( const std::string &ext );
			const std::string &getExtension() const;

			void setEditorInstance( InstancePtr logger );
			InstancePtr getEditorInstance() const;

			void setBaseName( const std::string &base );
			const std::string &getBaseName() const;

			bool checkUnsavedScripts() const;
			void saveAllUnsavedScripts();
			
			PageMap::iterator findScript( const std::string &name ){ return pages.find( name ); }
			PageMap::const_iterator findScript( const std::string &name ) const { return pages.find( name ); }

			ScriptEditorWidgetPtr currentScript();
			void closeScript(ScriptEditorWidgetPtr p);

			std::string nextName() const;

			bool hasScript( const std::string &name ) const;
			ScriptEditorWidgetPtr addScript(const std::string &path="");
			ScriptEditorWidgetPtr createScript(const std::string &name="", const std::string &content="");
			void removeScript( const std::string &name );
			
		protected slots:
			void modifiedStateChanged(ScriptEditorWidget *, bool);
		};
	};
}

#endif